#include "bulk_storage.h"
#include <stdio.h>

int main() {
  struct fileStore * fs;
  off_t block, block2;
  int x = 42, i;
  int *y;
  /*  long blockCount; */
  printf("Hello world! -- Lets do some testing.");

  fs = ds_open("TEST_file_store", "TEST_file_store.fat", (size_t)sizeof(int), (off_t)32);
  
  block2 = ds_newBlock(fs);

  block = ds_newBlock(fs);

  x = -1;
  ds_writeBlock(&x, fs, block);
  
  /*  blockCount = fs.blockCount; */

  ds_close(fs);

  fs = ds_open("TEST_file_store", "TEST_file_store.fat", sizeof(int), 0);

  
  y = (int*)ds_readBlock(fs, block);
  x = *y;
  printf("Block %ld contains %d Other block is %ld\n", (long int)block, x, (long int)block2);
  ds_releaseBlock(fs, block, y);

  ds_close(fs);

  printf("That was fun, now some performance evaluations.");

  fs = ds_open("big", "big.fat", sizeof(int[30]), 128);

  for(i = 0; i < 700000; i++) {
    off_t blockIdx = ds_newBlock(fs);
    int block[30];
    int j;
    for(j = 0; j < 30; j++) {
      block[j] = i;
    }
    ds_writeBlock(block, fs, blockIdx);
    if(! (i % 100000)) {
      printf("%ld\n", (long int)blockIdx);
    }

  }

  ds_close(fs);
  return 0;
}
